from django.contrib.auth.models import AbstractUser
from django.db import models
import uuid

# Create your models here.

class UserInfo(AbstractUser):
    Gender_CHOICES = (
        (1, "男"),
        (2, "女"),
        (3, "保密"),
    )

    # username = models.CharField(verbose_name='用户名', max_length=32, db_index=True)  # db_index=True 索引,搜索
    # email = models.EmailField(verbose_name='邮箱', max_length=32, null=True, blank=True)
    uuid = models.UUIDField(verbose_name='用户uuid', default=uuid.uuid4)
    mobile_phone = models.CharField(verbose_name='手机号', max_length=11)
    password = models.CharField(verbose_name='密码', max_length=32)
    avatar = models.ImageField(upload_to='avatar', default='avatar/default.png',
                               max_length=200, blank=True, null=True, verbose_name='用户头像')
    gender = models.SmallIntegerField(verbose_name='性别', choices=Gender_CHOICES, default=3)
    motto = models.CharField(verbose_name='格言', max_length=50, default='')
    intro = models.CharField(verbose_name='个人简介', max_length=150, default='')
    # follower = models.ManyToManyField('account.UserInfo', through='Follow', related_name='followers')
    # 每一名用户对应一个桶
    bucket = models.CharField(verbose_name='cos桶', max_length=128)
    region = models.CharField(verbose_name='cos区域', max_length=32)
    create_datetime = models.DateTimeField(verbose_name='创建时间', auto_now_add=True)

    def __str__(self):
        return self.username

    # 关注我的人
    @property
    def my_fans(self):
        return self.who_follow_me.all()

    # 我关注的人
    @property
    def my_follows(self):
        return self.my_follow.all()

    def my_friend(self):
        for i in self.my_follows:
            pass

